package ThreadPoolswithExecutorFramework_7_chapt;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class Main {

	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		System.out.println("executors framework");

		
		//Executors - Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, 
		//ThreadFactory, and Callable classes defined in this package.
		
		ExecutorService executor=Executors.newFixedThreadPool(10);
		
		for(int i=0;i<500;i++){
			Runnable worker=new MyRunnable(1000000L +i);
			executor.execute(worker);
		}
		// Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
		executor.shutdown();
		
 
        //Blocks until all tasks have completed execution after a shutdown request, 
		//or the timeout occurs, or the current thread is interrupted, whichever happens first.
		executor.awaitTermination(1000	, TimeUnit.MINUTES);
		
		
		/*
		 * The executor framework presented in the this chapter works with Runnables.
		 *  Runnable do not return result.
		 * 
		 * */
		
		/*
		 * In case the threads should return some value (result-bearing threads) then you can use the java.util.concurrent.Callable class.
		 * */
		
		
		
		System.out.println("all finished");
	}

}
